home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 May: Tool Chest / Dev.CD May 98 TC.toast / Tool Chest / Development Kits / HyperCard Related / APDA HyperCard Toolkits / HyperCard Serial Toolkit 2.6 / Source Code / closeSPort.p < prev    next >
Encoding:
Text File  |  1995-02-07  |  2.8 KB  |  102 lines  |  [TEXT/MPS ]

  1. (*
  2.     closeSPort [dontClose] -- Close the serial port driver, and release any buffer space associated with the input.
  3.         If the dontClose parameter is present, closeSPort frees the buffer space, and resets the port to known
  4.         values, but doesn't actually close the driver. This allows DTR to remain asserted.
  5.  
  6.     To compile and link this file using Macintosh Programmer's Workshop,
  7.  
  8.         pascal -w closeSPort.p
  9.         link -m ENTRYPOINT -o HyperCommands -rt XCMD=7031 -sn Main=closeSPort ∂
  10.             closeSPort.p.o "{MPW}"Libraries:interface.o "{MPW}"Libraries:Libraries:HyperXLib.o
  11.  
  12.     © Copyright 1987,88,89 by Apple Computer, Inc.
  13.  
  14.     Initial coding 9/87 by Harry R. Chesley.
  15. *)
  16.  
  17. {$R-}
  18.  
  19. {$S closeSPort }     { Segment name must be the same as the command name. }
  20.  
  21. unit DummyUnit;
  22.  
  23. interface
  24.  
  25. uses MemTypes, QuickDraw, OSIntf, HyperXCmd;
  26.  
  27. procedure EntryPoint(paramPtr: XCmdPtr);
  28.     
  29. implementation
  30.  
  31. procedure closeSPort(paramPtr: XCmdPtr); forward;
  32.  
  33. procedure EntryPoint(paramPtr: XCmdPtr);
  34.  
  35.     begin
  36.         closeSPort(paramPtr);
  37.     end;
  38.  
  39. procedure closeSPort(paramPtr: XCmdPtr);
  40.  
  41.     var i: integer;
  42.  
  43.     procedure Fail(errMsg: Str255); { set theResult and quit }
  44.         begin
  45.             paramPtr^.returnValue := PasToZero(paramPtr,errMsg);
  46.             exit(closeSPort);
  47.         end;
  48.  
  49.     {$I SPortUtil.inc}
  50.  
  51.     begin
  52.         if paramPtr^.paramCount > 1 then Fail('parameter count is not 0 or 1');
  53.  
  54.         SetUpSPortGlobals;
  55.  
  56.         if not ThisSPort.isOpen then Fail('port is not open');
  57.  
  58.         { Wait for the output to drain. (If he didn't want to wait, he should have done a killSPort first.) }
  59.         WaitForAllFree;
  60.         { If there's an input buffer allocated, deallocate it. }
  61.         if ThisSPort.inputBuffer <> nil then
  62.             begin
  63.                 if SerSetBuf(ThisSPort.portInDev,nil,0) <> noErr then Fail('SerSetBuf failed');
  64.                 DisposPtr(ThisSPort.inputBuffer);
  65.             end;
  66.         { Close the port. }
  67.         if paramPtr^.paramCount = 0 then
  68.             begin
  69.                 if CloseDriver(ThisSPort.portInDev) <> noErr then Fail('CloseDriver failed');
  70.                 if CloseDriver(ThisSPort.portOutDev) <> noErr then Fail('CloseDriver failed');
  71.             end;
  72.         { Dispose of all the output parmBlks. }
  73.         for i := 1 to MAXPARMBLKS do
  74.             begin
  75.                 if ThisSPort.parmBlks[i]^.ioBuffer <> nil then DisposPtr(ThisSPort.parmBlks[i]^.ioBuffer);
  76.                 DisposPtr(Ptr(ThisSPort.parmBlks[i]));
  77.             end;
  78.         { Reset everything to the default values and mark the port as closed. }
  79.         with Globals^^.ports[Globals^^.selectedPort] do
  80.             begin
  81.                 { Set the default byte format. }
  82.                 byteConfig := baud1200+stop10+noParity+data8;
  83.                 { Set the rest of the port defaults. }
  84.                 with shakes do
  85.                     begin
  86.                         fXOn := 0; fCTS := 0; errs := 0; evts := 0; fInX := 0;
  87.                     end;
  88.                 { Set no auto-linefeed, no echo, no edit, no strip top bits. }
  89.                 sendLFs := false;
  90.                 doEcho := false;
  91.                 doEdit := false;
  92.                 stripIncoming := true;
  93.                 autoWrap := false;
  94.                 currentColumn := 1;
  95.                 isOpen := false;
  96.                 { Clear out the input buffer pointer. }
  97.                 inputBuffer := nil;
  98.             end;
  99.     end;
  100.  
  101. end.
  102.